﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DAL.DateSet;
using DAL;
using DAL.DateSet.BrandTableAdapters;
namespace BLL.Wrapper
{
    public class BrandWrapper : BrandTableAdapter
    {
        public Brand.BrandDataTable getAll()
        {
            return GetData();
        }

        public  void deleteByID(int id)
        {
            HouseDiyHelper helpper = HouseDiyHelper.GetInstance();
            string sql = " delete from Brand where brandID = " + id.ToString();
            helpper.initOle();
            helpper.delete(sql);
        }

        public void updateARecord(Brand.BrandRow row)
        {
            Brand.BrandDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (Convert.ToInt32(table.Rows[i]["brandID"].ToString()) == row.brandID)
                {
                    table.Rows[i]["brandName"] = row.brandName;
                    table.Rows[i]["brandEnglishName"] = row.brandEnglishName;
                    table.Rows[i]["brandDesc"] = row.brandDesc;
                    table.Rows[i]["brandOrder"] = row.brandOrder;
                    table.Rows[i]["brandCreator"] = row.brandCreator;
                    table.Rows[i]["brandCreatDate"] = row.brandCreateDate;
                    table.Rows[i]["brandPicSrc"] = row.brandPicSrc;
                    break;
                }
            }
            Update(table);
        }

        public void addARecord(Brand.BrandRow row)
        {
            Insert(row.brandName, row.brandEnglishName, row.brandDesc, row.brandOrder, row.brandPicSrc, row.brandCreator, row.brandCreateDate);
        }

        public List<string> getBrandName()
        {
            Brand.BrandDataTable table = new Brand.BrandDataTable();
            List<string> list = new List<string>();
            table = getAll();
            for(int i = 0; i < table.Rows.Count; i++)
            {
                list.Add(table.Rows[i]["brandName"].ToString());
            }
            return list; 
        }

        public int getIDByName(string name)
        {
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            string sql = "select brandID from Brand where brandName = '" + name + "'";
            DataTable table = new DataTable();
            table = helper.getResultBySql(sql);
            return Convert.ToInt32(table.Rows[0][0].ToString());
        }
    }
}
